/*
 * MIT License
 * Copyright (c) 2021 -- wangxiaozhe
 */
package com.pearadmin.pro.repository.sys.rest;

import com.pearadmin.pro.common.aop.annotations.Log;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.base.page.PageResponse;
import com.pearadmin.pro.common.web.domain.Result;
import com.pearadmin.pro.repository.sys.domain.SysHost;
import com.pearadmin.pro.repository.sys.domain.SysInfo;
import com.pearadmin.pro.repository.sys.param.SysHostRequest;
import com.pearadmin.pro.repository.sys.service.SysHostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import static com.pearadmin.pro.common.constant.ControllerConstant.PREFIX_CMDB;

/**
 * @author wangxiaozhe
 */
@Api(tags = {"主机"})
@RestController
@RequestMapping(PREFIX_CMDB + "host")
@SuppressWarnings("unused")
public class SysHostController extends BaseController {

    @Resource
    private SysHostService sysHostService;

    /**
     * 查询主机列表
     *
     * @param request 查询参数
     */
    @GetMapping("page")
    @Log(title = "查询岗位")
    @ApiOperation(value = "查询主机")
    public Result<Object> page(SysHostRequest request){
        PageResponse<SysHost> res = sysHostService.page(request);
        return success(res);
    }

    /**
     * 查询主机运行时状态
     *
     * @param request 查询参数
     */
    @GetMapping("sysInfo")
    @Log(title = "查询主机运行状态")
    @ApiOperation(value = "查询主机运行状态")
    public Result<Object> sysInfo(SysHostRequest request) {
        SysInfo res = sysHostService.sysInfo(request);
        return success(res);
    }

    /**
     * 查询主机列表
     *
     * @param request 查询参数
     */
    @GetMapping("list")
    @Log(title = "查询主机")
    @ApiOperation(value = "查询主机")
    public Result<Object> list(SysHostRequest request) {
        List<SysHost> res = sysHostService.list(request);
        return success(res);
    }

    /**
     * 新增主机
     *
     * @param SysHost 主机实体
     * @return {@link Boolean}
     */
    @PostMapping("save")
    @Log(title = "新增主机")
    @ApiOperation(value = "新增主机")
    public Result<Boolean> save(@RequestBody SysHost SysHost){
        Boolean res = sysHostService.save(SysHost);
        return auto(res);
    }

    /**
     * 修改主机
     *
     * @param SysHost 主机实体
     * @return {@link Boolean}
     */
    @PutMapping("edit")
    @Log(title = "修改主机")
    @ApiOperation(value = "修改主机")
    public Result<Boolean> edit( @RequestBody SysHost SysHost){
        Boolean res = sysHostService.updateById(SysHost);
        return auto(res);
    }

    /**
     * 删除主机
     *
     * @param id 主机编号
     * @return {@link Boolean}
     */
    @DeleteMapping("remove")
    @Log(title = "删除主机")
    @ApiOperation(value = "删除主机")
    public Result<Boolean> remove(@RequestParam String id){
        Boolean res = sysHostService.removeById(id);
        return auto(res);
    }

    /**
     * 批量删除
     *
     * @param ids 主机编号
     * @return {@link Boolean}
     */
    @DeleteMapping("removeBatch")
    @Log(title = "删除主机")
    @ApiOperation(value = "删除主机")
    public Result<Boolean> removeBatch(@RequestParam List<String> ids) {
        Boolean res = sysHostService.removeByIds(ids);
        return auto(res);
    }

}
